﻿using System;
using System.Web.UI;
using Medianamik.Core.Sugar;
using UserAgentDetection;

namespace Medianamik.DummyWebSite.Presentation.MasterPages
{
    public class BaseMasterPage : MasterPage
    {
        public IBasePage CurrentBasePage
        {
            get
            {
                return (IBasePage)Page;
            }
        }


        protected string MetaKeywords
        {
            get { return CurrentBasePage.CurrentWebPage.MetaKeywords; }
        }

        protected string MetaDescription
        {
            get
            {
                return !string.IsNullOrEmpty(CurrentBasePage.CurrentWebPage.MetaDescription)
                           ? CurrentBasePage.CurrentWebPage.MetaDescription
                           : MetaKeywords;
            }
        }

        public string BrowserTitle
        {
            get
            {
                if (!string.IsNullOrEmpty(CurrentBasePage.CurrentWebPage.BrowserTitle))
                {
                    return CurrentBasePage.CurrentWebPage.BrowserTitle;
                }
                return CurrentBasePage.CurrentWebPage.Name + " | " + "DefaultBrowserTitle".Translate();
            }
        }

        public static string GetSiteCopyrightYear(int startYear)
        {
            return startYear + (DateTime.Today.Year > startYear ? "-" + DateTime.Today.Year : String.Empty);
        }

        public string BodyId { get; set; }
        public string BodyCss { get; set; }

        private string _cssUserAgent;
        public string CssUserAgent
        {
            get
            {
                if (string.IsNullOrEmpty(_cssUserAgent))
                {
                    var cssUserAgent = new CssUserAgent(Request);
                    _cssUserAgent = cssUserAgent.GetCssUserAgent();
                }
                return _cssUserAgent;
            }
        }
    }
}
